home *** CD-ROM | disk | FTP | other *** search
- /*
- * DETUtilities.h
- * Copyright © 1992 Apple Computer Inc. All Rights Reserved.
- *
- * This is a collection of utility functions that simplify
- * programming OCE Directory Templates (CSAM) files. They
- * provide access to template properties and a few other
- * common bits of information. These functions are independent
- * of DTS Sample CSAM.
- */
-
- #include "DETUtilities.h"
- #include <Errors.h>
- #ifndef LogErrorX
- #include "Audit.h"
- #ifndef kCSAMCreatorID
- #define kCSAMCreatorID 'Pdsm'
- #elif kCSAMCreatorID != 'Pdsm'
- << error, the above won't work >>
- #endif
- #define LogErrorX(who, status) do { \
- if (status != noErr) { \
- AuditStatusLocation( \
- GetAuditPtr(kCSAMCreatorID), \
- who, status \
- ); \
- } \
- } while (0)
- #endif
-
- /*
- * Add a string to the Directory menu.
- */
- pascal OSErr
- AddToMenu(
- DETCallBlockPtr callBlockPtr,
- short property,
- short parameter,
- RString *text,
- Boolean isSeparator
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
- typedef struct RString1 {
- RStringHeader
- Byte body[sizeof (Byte)];
- } RString1;
- RString1 separator;
-
-
- cbb.addMenu.reqFunction = kDETcmdAddMenu;
- cbb.addMenu.property = property;
- cbb.addMenu.target.selector = kDETSelf;
- if (isSeparator == FALSE)
- cbb.addMenu.name = text;
- else {
- separator.charSet = smRoman;
- separator.dataLength = sizeof (Byte);
- separator.body[0] = '-';
- cbb.addMenu.name = (RString *) &separator;
- }
- cbb.addMenu.parameter = parameter;
- cbb.addMenu.addAfter = -1;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DAMu', status);
- return (status);
- }
-
- /*
- * Add/change an item to the template property database.
- * property The property to add
- * newValue A pointer to the datum
- * newValueSize The size of the datum
- * markAsChanged Mark database "changed"
- * This function does the actual database manipulation.
- * Normally, programs call SetBinaryProperty, SetNumProperty,
- * or SetRStringProperty to set particular data types.
- *
- * Note: this assumes that all the new values are in the same
- * position for Number, Binary, and RString properties
- */
- pascal OSErr
- SetPropertyCommon(
- DETCallBlockPtr callBlockPtr,
- DETCallFunctions function,
- short property,
- void *newValue,
- Size newValueSize,
- Boolean markAsChanged
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.setPropertyBinary.reqFunction = function;
- cbb.setPropertyBinary.property = property;
- cbb.setPropertyBinary.target.selector = kDETSelf;
- cbb.setPropertyBinary.newValue = newValue;
- cbb.setPropertyBinary.newValueSize = newValueSize;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DSPC', status);
- if (status == noErr && markAsChanged) {
- status = SetPropertyChanged(callBlockPtr, property, true);
- LogErrorX('DSPC', status);
- }
- return (status);
- }
-
- /*
- * Add/change a numeric property.
- * See SetPropertyCommon for the common parameters.
- * newValue The property value.
- */
- pascal OSErr
- SetNumProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- long newValue,
- Boolean markAsChanged
- )
- {
- OSErr status;
-
- status = SetPropertyCommon(
- callBlockPtr,
- kDETcmdSetPropertyNumber,
- property,
- (void *) newValue,
- 0,
- markAsChanged
- );
- return (status);
- }
-
- /*
- * Add/change a binary (untyped) property.
- * See SetPropertyCommon for the common parameters.
- * newValue -> the new datum
- * newValueSize Datum size
- */
- pascal OSErr
- SetBinaryProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- Ptr newValue,
- Size newValueSize,
- Boolean markAsChanged
- )
- {
- OSErr status;
-
- status = SetPropertyCommon(
- callBlockPtr,
- kDETcmdSetPropertyBinary,
- property,
- newValue,
- newValueSize,
- markAsChanged
- );
- return (status);
- }
-
- /*
- * Add/change a RString property.
- * See SetPropertyCommon for the common parameters.
- * newValue The new string contents
- */
- pascal OSErr
- SetRStringProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- RString *newValue,
- Boolean markAsChanged
- )
- {
- OSErr status;
-
- status = SetPropertyCommon(
- callBlockPtr,
- kDETcmdSetPropertyRString,
- property,
- newValue,
- 0,
- markAsChanged
- );
- return (status);
- }
-
- /*
- * Return the value of a numeric property
- * result Address of the desired value
- */
- pascal OSErr
- GetNumProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- long *result
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getPropertyNumber.reqFunction = kDETcmdGetPropertyNumber;
- cbb.getPropertyNumber.property = property;
- cbb.getPropertyNumber.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DGNP', status);
- *result = cbb.getPropertyNumber.propertyValue;
- return (status);
- }
-
- pascal OSErr
- GetBinaryProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- Handle *result
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getPropertyBinary.reqFunction = kDETcmdGetPropertyBinary;
- cbb.getPropertyBinary.property = property;
- cbb.getPropertyBinary.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DGBP', status);
- *result = cbb.getPropertyBinary.propertyValue;
- return (status);
- }
-
- /*
- * Return the value of a RString property
- * result Gets a pointer to the RString value
- */
- pascal OSErr
- GetRStringProperty(
- DETCallBlockPtr callBlockPtr,
- short property,
- RString ***result
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getPropertyRString.reqFunction = kDETcmdGetPropertyRString;
- cbb.getPropertyRString.property = property;
- cbb.getPropertyRString.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DGRP', status);
- *result = cbb.getPropertyRString.propertyValue;
- return (status);
- }
-
- pascal OSErr
- GetBinaryPropertySize(
- DETCallBlockPtr callBlockPtr,
- short property,
- Size *size
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getPropertyBinarySize.reqFunction = kDETcmdGetPropertyBinarySize;
- cbb.getPropertyBinarySize.property = property;
- cbb.getPropertyBinarySize.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DGPS', status);
- *size = cbb.getPropertyBinarySize.propertyBinarySize;
- return (status);
- }
-
- /*
- * Mark property "dirty"
- */
- pascal OSErr
- DirtyProperty(
- DETCallBlockPtr callBlockPtr,
- short property
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.dirtyProperty.reqFunction = kDETcmdDirtyProperty;
- cbb.dirtyProperty.property = property;
- cbb.dirtyProperty.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('Dirt', status);
- return (status);
- }
-
- /*
- * Mark property "changed" if the flag is TRUE.
- */
- pascal OSErr
- SetPropertyChanged(
- DETCallBlockPtr callBlockPtr,
- short property,
- Boolean isPropertyChanged
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.setPropertyChanged.reqFunction = kDETcmdSetPropertyChanged;
- cbb.setPropertyChanged.property = property;
- cbb.setPropertyChanged.target.selector = kDETSelf;
- cbb.setPropertyChanged.propertyChanged = isPropertyChanged;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('DSPC', status);
- return (status);
- }
-
- /*
- * Return a pointer to the DSSSpec for this template
- */
- pascal OSErr
- GetMyDSSpec(
- DETCallBlockPtr callBlockPtr,
- short *refNum,
- PackedDSSpec ***pDsSpec
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
- cbb.getDSSpec.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GDSp', status);
- *pDsSpec = cbb.getDSSpec.dsSpec;
- *refNum = cbb.getDSSpec.refNum;
- return (status);
- }
-
- /*
- * Get the number of items selected by the user.
- */
- pascal OSErr
- GetNumSelectedItems(
- DETCallBlockPtr callBlockPtr,
- long *result
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.selectedSublistCount.reqFunction = kDETcmdSelectedSublistCount;
- cbb.selectedSublistCount.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GNSI', status);
- *result = cbb.selectedSublistCount.count;
- return (status);
- }
-
- /*
- * GetNthSelectedItem allows the program to iterate
- * through the items selected by a user.
- */
- pascal OSErr
- GetNthSelectedItem(
- DETCallBlockPtr callBlockPtr,
- long itemNumber,
- PackedDSSpec ***pDsSpec,
- short *refNum
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
- cbb.getDSSpec.target.selector = kDETSelectedSublistItem;
- cbb.getDSSpec.target.aspectName = NULL;
- cbb.getDSSpec.target.itemNumber = itemNumber;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GNth', status);
- *pDsSpec = cbb.getDSSpec.dsSpec;
- *refNum = cbb.getDSSpec.refNum;
- return (status);
- }
-
- pascal OSErr
- OpenDSSpec(
- DETCallBlockPtr callBlockPtr,
- PackedDSSpec *dsSpec
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.openDSSpec.reqFunction = kDETcmdOpenDSSpec;
- cbb.openDSSpec.dsSpec = dsSpec;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('ODSS', status);
- return (status);
- }
-
- pascal OSErr
- GetMyFSSpec(
- DETCallBlockPtr callBlockPtr,
- FSSpec *fsSpecPtr
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getTemplateFSSpec.reqFunction = kDETcmdGetTemplateFSSpec;
- cbb.getTemplateFSSpec.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GFSp', status);
- if (status == noErr)
- *fsSpecPtr = cbb.getTemplateFSSpec.fsSpec;
- return (status);
- }
-
- pascal OSErr
- GetMenuItemRString(
- DETCallBlockPtr callBlockPtr,
- short property,
- long parameter,
- RString ***result
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.menuItemRString.reqFunction = kDETcmdMenuItemRString;
- cbb.menuItemRString.property = property;
- cbb.menuItemRString.target.selector = kDETSelf;
- cbb.menuItemRString.itemParameter = parameter;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GMRS', status);
- *result = cbb.menuItemRString.rString;
- if (status == paramErr)
- status = noErr;
- return (status);
- }
-
- pascal OSErr
- RequestSync(
- DETCallBlockPtr callBlockPtr
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.requestSync.reqFunction = kDETcmdRequestSync;
- cbb.requestSync.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('Sync', status);
- return (status);
- }
-
- pascal OSErr
- SaveProperty(
- DETCallBlockPtr callBlockPtr,
- long property
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.saveProperty.reqFunction = kDETcmdSaveProperty;
- cbb.saveProperty.property = property;
- cbb.saveProperty.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('SavP', status);
- return (status);
- }
-
- pascal OSErr
- GetCustomViewBounds(
- DETCallBlockPtr callBlockPtr,
- short property,
- Rect *bounds
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getCustomViewBounds.reqFunction = kDETcmdGetCustomViewBounds;
- cbb.getCustomViewBounds.property = property;
- cbb.getCustomViewBounds.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GVbd', status);
- *bounds = cbb.getCustomViewBounds.bounds;
- return (status);
- }
-
- pascal OSErr
- GetPropertyEditable(
- DETCallBlockPtr callBlockPtr,
- short property,
- Boolean *isEditable
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.getPropertyEditable.reqFunction = kDETcmdGetPropertyEditable;
- cbb.getPropertyEditable.property = property;
- cbb.getPropertyEditable.target.selector = kDETSelf;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('GPEd', status);
- *isEditable = cbb.getPropertyEditable.propertyEditable;
- return (status);
- }
-
- pascal OSErr
- SetPropertyEditable(
- DETCallBlockPtr callBlockPtr,
- short property,
- Boolean isEditable
- )
- {
- OSErr status;
- DETCallBackBlock cbb;
-
- cbb.setPropertyEditable.reqFunction = kDETcmdSetPropertyEditable;
- cbb.setPropertyEditable.property = property;
- cbb.setPropertyEditable.target.selector = kDETSelf;
- cbb.setPropertyEditable.propertyEditable = isEditable;
- status = CallBackDET(callBlockPtr, &cbb);
- LogErrorX('SPed', status);
- return (status);
- }
-
-